from typing import Optional

from pydantic import BaseModel, Field
from sqlalchemy import Column, String, BigInteger, DECIMAL,Float
from toollib.utils.now2timestamp_ import now2timestamp

from app.datatype import DeclBase, filter_fields



class MilvusContent(DeclBase):
    __tablename__ = "milvus_content"

    id = Column(BigInteger, primary_key=True, autoincrement=True, comment="主键")
    #milvus_index
    milvus_index_id = Column(BigInteger, nullable=False, comment="milvus索引id")
    milvus_index = Column(String(200), nullable=False, comment="milvus索引名称")
    #file_name
    file_name = Column(String(200), nullable=False, comment="文件名称")
    file_path = Column(String(500), nullable=False, comment="文件路径")
    #file_size 单位为kb
    file_size = Column(Float, nullable=False, comment="文件大小")
    create_id = Column(String(20), nullable=False, comment="用户ID")
    update_id = Column(String(20), nullable=False, comment="用户ID")
    created_at = Column(BigInteger, default=now2timestamp, comment="创建时间")
    updated_at = Column(BigInteger, default=now2timestamp, onupdate=now2timestamp, comment="更新时间")
    is_deleted = Column(BigInteger, default=0, comment="删除状态，0未删除，1已删除")
    #上传状态 完成 未完成
    upload_status = Column(BigInteger, default=0, comment="上传状态，0未完成，1已完成 3失败")

class MilvusContentDetailMdl(BaseModel):
    id: str = Field(...)
    # #
    name: str = None

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )

#创建milvus内容
class MilvusContentCreateMdl(BaseModel):
    milvus_index_id: int = Field(default=1, description="milvus索引ID")
    milvus_index: str = Field(default="", description="milvus索引名称")
    file_name: str = Field(default="", description="文件名称")
    file_path: str = Field(default="", description="文件路径")
    file_size: float = Field(default=0, description="文件大小，单位为KB")

class MilvusContentCreateBatchMdl(BaseModel):
    milvus_index_id: int = Field(default=1, description="milvus索引ID")
    milvus_index: str = Field(default="", description="milvus索引名称")
    file_name: str = Field(default="", description="文件名称")
    file_path: str = Field(default="", description="文件路径")
    file_size: float = Field(default=0, description="文件大小，单位为KB")
    milvus_content_id:  int = Field(default=1, description="milvus索引ID")

#删除知识库文件
class MilvusContentDeleteMdl(BaseModel):
    id: int = Field(..., description="主键id")
    milvus_index: str = Field(..., description="milvus索引名称")
    file_name: str = Field(..., description="文件名称")


class MilvusContentListFindMdl(BaseModel):
    milvus_index_id: int = Field(None, description="milvus索引ID")
    find_name: Optional[str]  = Field(None, description="搜索名称")


    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
#获取知识库文件列表
class MilvusContentListMdl(BaseModel):
    id: int = Field(..., description="主键ID")
    milvus_index_id: int = Field(..., description="milvus索引ID")
    milvus_index: str = Field(..., description="milvus索引名称")
    file_name: str = Field(..., description="文件名称")
    file_path: str = Field(..., description="文件路径")
    file_size: float = Field(default=0, description="文件大小，单位为KB")
    upload_status: int = Field(default=0, description="上传状态，0未完成，1已完成 3失败")
    created_at: int = Field(..., description="上传时间")

    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls,
            exclude=[]
        )
class MilvusFilePath(BaseModel):
    path: str = Field(..., description="文件路径")

class FileList(BaseModel):
    file_name: str = Field("", description="文件路径")
    @classmethod
    def response_fields(cls):
        return filter_fields(
            cls
        )
